<?php

namespace plugin\admin\app\controller;

use support\Request;
use support\Response;
use plugin\admin\app\model\UserFinancialRecord;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;

/**
 * 用户资产变更记录表
 */
class UserFinancialRecordController extends Crud
{

    /**
     * @var UserFinancialRecord
     */
    protected $model = null;

    /**
     * 构造函数
     * @return void
     */
    public function __construct()
    {
        $this->model = new UserFinancialRecord;
    }

    /**
     * 浏览
     * @return Response
     */
    public function index(): Response
    {
        $type = [];
        foreach (USER_CAPITAL_TYPE as $key => $val) {
            $type[] = [
                'value' => $val,
                'name' => $key
            ];
        }
        $status = [];
        foreach (USER_CAPITAL_STATUS as $key => $val) {
            $status[] = [
                'value' => $val,
                'name' => $key
            ];
        }

        return view('user-financial-record/index', ['type' => json_encode($type),'status' => json_encode($status)]);
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return parent::insert($request);
        }
        return view('user-financial-record/insert');
    }

    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return parent::update($request);
        }
        return view('user-financial-record/update');
    }

}
